package yl.hs.bmipfull.controllers.dataCockpit;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.production.IProductionRecordService;
import yl.hs.bmipfull.service.vehiclemanage.ITruckInfoService;
import yl.hs.bmipfull.viewmodels.WebResult;
import yl.hs.bmipfull.service.dataCockpit.IProductionCockpitService;
import yl.hs.bmipfull.viewmodels.dataCockpit.DataCockpitNumberModel;
import yl.hs.bmipfull.viewmodels.dataCockpit.ProductOutputModel;

import java.awt.geom.Ellipse2D;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @author 谢东
 * @apiNote 数据驾驶舱--生产看板
 * @since 2022/8/30 15:20 创建
 */
@RequestMapping("/api/dataCockpit/productionCockpit")
@Api(value = "数据驾驶舱--生产看板", tags = "数据驾驶舱--生产看板")
@RestController
public class ProductionCockpitController extends ControllerBase {

    @Autowired
    ITruckInfoService truckInfoService;
    @Autowired
    IProductionCockpitService service;
    @Autowired
    IProductionRecordService recordService;



    @ApiOperation(value = "生产看板--生产任务完成进度", notes = "生产任务完成进度")
    @GetMapping("/ProductionTaskProgress")
    public WebResult completionRate(String timeType) {
        try {
            return success("查询成功", service.getActualProduction(timeType));
        } catch (Exception ee) {
            return error(ee);
        }

    }


    /**
     * 各产品产量分析-完成率指针图
     *
     * @param timeType
     * @return
     */
    @ApiOperation(value = "生产看板--各产品产量分析", notes = "各产品产量分析")
    @GetMapping("/CurrentPointerDiagram")
    public WebResult CurrentPointerDiagram(String timeType) {
        try {
            return success("查询成功", service.getRingPeriod(timeType));
        } catch (Exception ee) {
            return error(ee);
        }
    }


    @ApiOperation(value = "生产看板-车辆运输情况分析", notes = "生产看板-车辆运输情况分析")
    @RequestMapping(value = "/truckRunningSituation", method = RequestMethod.GET)
    public WebResult truckRunningSituation() {
        var stateAll = truckInfoService.findStateAll();
        return success("查询成功", stateAll);
    }

    @ApiOperation(value = "生产看板-生产时序图", notes = "生产看板-车辆运输情况分析")
    @RequestMapping(value = "/ProductionSequenceDiagram", method = RequestMethod.GET)
    public WebResult ProductionSequenceDiagram() {
        var result = recordService.queryProductionRecordByHouse();
        return success("查询成功", result);
    }

    @ApiOperation(value = "生产看板-年度生产重量趋势分析", notes = "生产看板-年度生产重量趋势分析")
    @RequestMapping(value = "/AnnualProductionWeight", method = RequestMethod.GET)
    public WebResult AnnualProductionWeight() {
        var result = recordService.queryProductionRecordByMonthon();
        return success("查询成功", result);
    }



    @ApiOperation(value = "各产品生产重量及占比", notes = "   各产品生产重量-直方图")
    @GetMapping("/EachWeight")
    public WebResult EachWeight( String timeType){
        var result=service.getProportionEachProduct("砂浆", timeType);
        if (result.size()<=0){
            return success("查询成功",null);
        }
        return success("查询成功",result);
    }




}






